<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>传统分页效果</title>
	<style type="text/css">
		table{
			width: 700px;
			border: 1px solid #ccc;
			border-collapse: collapse;
			margin: auto;
		}
		h2{
			width: 700px;
			margin: auto;
			background-color: orange;
			text-align: center;
		}
		#head{
			text-align: center;
			font-weight: bold;
		}
		tr{
			text-align: center;
		}
		td{
			border: 1px solid #ccc;
		}
		div#pagelist{
			width: 900px;
			/*border: 1px solid #ccc;*/
			margin: 0px auto;
			font-size: 11px;
		}
	</style>
</head>
<body>
	<?php 
	header('content-type:text/html;charset=utf8');
	//引入分页类文件
	require './Page.class.php';
	try {
		$dsn="mysql:host=localhost;dbname=demo";
		$db=new PDO($dsn,'root','');
		$db->query('set names utf8');
		$db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
		//1.记录总数
		$sql1="select count(*) from auth";
		$num_statement=$db->query($sql1);
		$num=$num_statement->fetchColumn();
		// 2.每页显示的数量
		$size=5;
		// 3.获取当前页码
		$current_page=isset($_GET['page'])?$_GET['page']:1;
		$start=($current_page-1)*$size;
		//获取数据
		$sql="select * from auth limit $start,{$size}";
		// echo $sql;
		$statement=$db->query($sql);
		$data=$statement->fetchAll(PDO::FETCH_ASSOC);
		// var_dump($data);
	} catch (PDOException $e) {
		$e->getMessage();
	}
	//使用分页类
	$page=new Page($num,$size);
	$pagelist=$page->fpage();
	?>	
	<!-- 显示数据 -->
	<!-- <h2>传统分页效果</h2> -->
	<table>
		<tr id="head">
			<td>ID</td>
			<td>NAME</td>
			<td>PID</td>
		</tr>

			<?php foreach ($data as $k => $v): ?>
			<tr>
				<td><?php echo $v['auth_id'] ?></td>
				<td><?php echo $v['auth_name'] ?></td>
				<td><?php echo $v['auth_pid'] ?></td>
			</tr>			
			<?php endforeach ?>

	</table>
	<div id="pagelist"><?php echo $pagelist ?></div>

</body>
</html>
